package org.windowkit.toolkit.icons;

import java.awt.Component;
import java.awt.Graphics2D;

import javax.swing.SwingConstants;

/**
 * @author Eric Lundin
 *
 */
public class ArrowIcon extends RotatableIcon {
	/**
	 * @param direction
	 *            The direction the arrow should face. Must be one of:
	 *            <ul>
	 *            <li>SwingConstants.NORTH</li>
	 *            <li>SwingConstants.SOUTH</li>
	 *            <li>SwingConstants.WEST</li>
	 *            <li>SwingConstants.EAST</li>
	 *            </ul>
	 */
	public ArrowIcon(final int direction) {
		super(direction);

		switch (direction) {
		case SwingConstants.NORTH:
		case SwingConstants.SOUTH:
		case SwingConstants.EAST:
		case SwingConstants.WEST:
			this.direction = direction;
			break;
		default:
			throw new IllegalArgumentException(
					"Arrow Icon direction must be one of: SwingConstants.NORTH, "
							+ "SwingConstants.SOUTH, SwingConstants.EAST,"
							+ " or SwingConstants.WEST ");
		}
	}

	/*
	 *  (non-Javadoc)
	 * @see org.windowkit.toolkit.icons.RotatableIcon#drawIcon(java.awt.Component, java.awt.Graphics2D)
	 */
	@Override
	public void drawIcon(final Component c, final Graphics2D g2) {
		g2.setColor(c.getForeground());
		g2.fillPolygon(getXPoints(), getYPoints(), 3);
	}

	/**
	 * Get the x values for the points making up the arrow.
	 *
	 * @param height
	 *            The component height.
	 * @param width
	 *            The component width.
	 * @return The x values for the arrow's points.
	 */
	public int[] getXPoints() {
		int[] xPoints = new int[3];
		xPoints[0] = -getIconWidth() / 2;
		xPoints[1] = -getIconWidth() / 2;
		xPoints[2] = getIconWidth() / 2;
		return xPoints;
	}

	/**
	 * Get the y values for the points making up the arrow.
	 *
	 * @param height
	 *            The component height.
	 * @param width
	 *            The component width.
	 * @return The y values for the arrow's points.
	 */
	public int[] getYPoints() {
		int[] yPoints = new int[3];
		yPoints[0] = -getIconHeight() / 2;
		yPoints[1] = getIconHeight() / 2;
		yPoints[2] = 0;
		return yPoints;
	}
}
